package com.ssi.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.ssi.domain.user.User;

public class CommonAction implements ServletRequestAware,  
ServletResponseAware, SessionAware{
	protected HttpServletResponse response;  
    protected HttpServletRequest request;  
    protected Map<String, Object> session; 
	
	
	
	public String getParameters(String key){
		return request.getParameter(key);
		
	}
	public Object getSessionAttribute(String key){
		return session.get(key);
		
	}
	public void setSessionAttribute(String key,Object value){
		session.put(key, value);
	}
	public void setAttribute(String key,Object value){
		Map<String, Object> parameters = ActionContext.getContext().getParameters();
		parameters.put(key, value);
		ActionContext.getContext().setParameters(parameters);
	}
	
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}
	public void setServletResponse(HttpServletResponse response) {
		this.response=response;
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
	}
	public void setValueStack(String key, Object value){
		   ValueStack valueStack=ServletActionContext.getContext().getValueStack();
		   valueStack.set(key, value);

	}
	public User getUser(){
		
		if(getSessionAttribute("user")==null){
			return null;
		}else{
			return (User) getSessionAttribute("user");
			
		}
	}
}
